﻿namespace 超市系统
{
    public abstract class CalFather
    {
        /// <summary>
        /// 打折父类
        /// </summary>
        /// <param name="realMoney"></param>
        /// <returns></returns>
        public abstract double GetTotalMoney(double realMoney);
    }

    /// <summary>
    /// 不打折
    /// </summary>
    internal class CalNormal : CalFather
    {
        public override double GetTotalMoney(double realMoney)
        {
            return realMoney;
        }
    }

    /// <summary>
    /// 按折扣来打折
    /// </summary>
    internal class CalRate : CalFather
    {
        private double rate;
        public double Rate { get => rate; set => rate = value; }

        public CalRate(double rate)
        {
            Rate = rate;
        }

        public override double GetTotalMoney(double realMoney)
        {
            return realMoney * Rate;
        }
    }

    /// <summary>
    /// 满（）送（）
    /// </summary>
    internal class CalMN : CalFather
    {
        private double buy;
        private double give;

        public double Buy { get => buy; set => buy = value; }
        public double Give { get => give; set => give = value; }

        public CalMN(double buy, double give)
        {
            Buy = buy;
            Give = give;
        }

        public override double GetTotalMoney(double realMoney)
        {
            if (realMoney >= Buy)
            {
                return realMoney - (int)(realMoney / Buy) * Give;
            }
            else
            {
                return realMoney;
            }
        }
    }
}